//
//  FieldCell.m
//  SimpleHappy
//
//  Created by lanou on 15/11/23.
//  Copyright © 2015年 RockyFung. All rights reserved.
//

#import "FieldCell.h"
#import "Define.h"
#import "UIImageView+WebCache.h"

@interface FieldCell()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIImageView *iconImage;

@end



@implementation FieldCell



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = NO;
        
        CGFloat width = KScreenWidth - 10;
        CGFloat height = KScreenHeight / 6;
        
        // 图片
        CGFloat iconHeight = height / 1.2;
        CGFloat iconWidth = iconHeight * 600/390;
        self.iconImage = [[UIImageView alloc]initWithFrame:CGRectMake(5, 10, iconWidth, iconHeight)];
        self.iconImage.image = [UIImage imageNamed:@"placeholder@2x.png"];
        [self.contentView addSubview:_iconImage];
        
        // 标题
        self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(iconWidth + 20, 10, width / 1.8 , KScreenWidth / 7.5)];
        self.titleLabel.numberOfLines = 2;
//        self.titleLabel.backgroundColor = [UIColor cyanColor];
        self.titleLabel.textAlignment = UIControlContentVerticalAlignmentTop;
        self.titleLabel.textAlignment = NSTextAlignmentLeft;
        self.titleLabel.text = @"";
        [self.contentView addSubview:_titleLabel];
     
    }
    return self;
}

// 根据字符串和字体求字符串的高度
- (CGSize)stringSizeWithFont:(UIFont *)font string:(NSString *)string width:(CGFloat)width
{
    CGRect rect = [string boundingRectWithSize:CGSizeMake(width, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil];
    return rect.size;
}

- (void)setModel:(FieldModel *)model
{
    _model = model;
    
    // 设置图片
    [self.iconImage sd_setImageWithURL:[NSURL URLWithString:self.model.picUrl]];
    
    // 设置标题
    self.titleLabel.text = self.model.title;
    
}

@end
